﻿using System;
using System.Collections.Generic;
using System.Text;

namespace VideoPoker
{
	internal static class Sounds
	{
		[System.Runtime.InteropServices.DllImport("winmm.dll", EntryPoint = "PlaySound", ExactSpelling = false, CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
		public static extern int PlaySound(string Name, int hMod, int Flags);
		// Name specifies the sound file when the SND_FILENAME flag is set
		// hMod specifies an executable file handle
		// hmod must be Nothing if the SND_RESOURCE flag is not set
		// Flags specifies which flags are set
		private const int SND_SYNC = 0X0; // Play synchronously
		private const int SND_ASYNC = 0X1; // Play asynchronously
		private const int SND_FILENAME = 0X20000; // Name is file name
		private const int SND_RESOURCE = 0X40004; // Name is resource name or atom

		private static string[] Files = new string[] { 
			"betin.wav",
			"cashout.wav",
			"click.wav",
			"coinin.wav",
			"deal.wav",
			"prewin.wav",
			"win.wav",
			"winner.wav"
		};

		// Provides better inline documentation (self desc.)
		public enum LocalFile : int
		{
			BetIn,
			Cashout,
			Click,
			CoinIn,
			Deal,
			PreWin,
			Win,
			Winner
		}

		public static void PlaySoundFile(string Filename)
		{
			// Plays a sound from filename
			try
			{
				PlaySound(Filename, 0, SND_FILENAME | SND_ASYNC);
			}
			catch (Exception /*ex*/)
			{
            //empty catch
			}
		}


		public static void PlaySounds(LocalFile Sound)
		{
			PlaySoundFile(Files[(int)Sound]);
		}

	}
}
